package com.fauks.ssm.springbyanno.config;

import com.fauks.ssm.springbyanno.bean.Cat;
import com.fauks.ssm.springbyanno.bean.PersonFactoryBean;
import com.fauks.ssm.springbyanno.condition.LinuxCondition;
import com.fauks.ssm.springbyanno.condition.WinCondition;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;

/**
 * 配置类：等同于配置文件
 */
//加载外部配置文件
/*@PropertySource(value = {"classpath:db.properties"})
//声明配置类
@Configuration
//开启包扫描
@ComponentScan(value = "com.fauks.ssm.springbyanno")*/

//@Import({Color.class, MyImportSelector.class, MyImportBeanDefinitionRegistrar.class})
public class IOCConfig {

    @Value("${jdbc.driverClass}")
    public String driver;

    @Bean
    public Cat cat() {
        System.out.println(driver);
        return new Cat();
    }

    //使用FactoryBean导入
    @Bean
    public PersonFactoryBean personFactoryBean() {
        return new PersonFactoryBean();
    }

    @Conditional(WinCondition.class)
    @Bean(name = "win")
    public Cat catWindows() {
        return new Cat(12, "win");
    }

    //如果系统是linux才给ioc容器注册linux，否则不注册
    @Conditional(LinuxCondition.class)
    @Bean(name = "linux")
    public Cat catLinux() {
        return new Cat(102, "linux");
    }

}
